package com.tarena.lbs.passport.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.common.passport.converter.LoginConverter;
import com.tarena.lbs.passport.service.LoginService;
import com.tarena.lbs.pojo.passport.bo.AdminBO;
import com.tarena.lbs.pojo.passport.bo.UserBO;
import com.tarena.lbs.pojo.passport.param.AdminLoginParam;
import com.tarena.lbs.pojo.passport.param.UserLoginParam;
import com.tarena.lbs.pojo.passport.vo.LoginVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LoginController {
    /**
     * 后台登录
     */
    @Autowired
    private LoginService loginService;
    @Autowired
    private LoginConverter loginConverter;
    @PostMapping("/passport/admin/login")
    public Result<LoginVO> login(AdminLoginParam adminLoginParam)
        throws BusinessException {
        AdminBO adminBO=loginService.doLogin(adminLoginParam);
        LoginVO loginVo= loginConverter.adminbo2loginvo(adminBO);
        return new Result<>(loginVo);
    }
    /**
     * 前台登录
     */
    @PostMapping("/passport/user/login")
    public Result<LoginVO> login(UserLoginParam userLoginParam) throws BusinessException {
        UserBO userBO=loginService.doLogin(userLoginParam);
        LoginVO loginVO =loginConverter.userbo2loginvo(userBO);
        return new Result<>(loginVO);
    }
}
